part of 'cross_view.dart';

class CrossPassView extends GetView<CrossController> {
  final CrossPassController c;
  final bool highPass;
  const CrossPassView(this.c, {Key? key, this.highPass = false})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<CrossPassController>(
        init: c,
        builder: (controller) {
          printInfo(info: 'build cross slider freq->${c.freq}');
          return _child(context);
        });
  }

  Widget _child(BuildContext context) {
    var w = (Get.width / 3) * 0.7;
    Widget child = CircularSlider(
      size: w,
      min: 20,
      max: 20000,
      initialValue: c.freq.value.toDouble(),
      onChange: (freq) => c.setFreq(freq.toInt()),
      onIncrease: c.increaseFreq,
      onDecrease: c.decreaseFreq,
      increaseOffset: Offset(-5, -8),
      decreaseOffset: Offset(5, -8),
      innerWidget: (p0) {
        return SizedBox(
          height: w,
          child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              mainAxisSize: MainAxisSize.min,
              children: [
                SizedBox(
                  height: 15,
                ),
                Obx(() => UnitText(
                      prefix: 'Freq',
                      text: c.freq.toString(),
                      focusNode: c.focusNode,
                      controller: c.textEditingControllerFreq,
                      onEditingComplete: () {
                        c
                          ..focusNode.unfocus()
                          ..updateFreq();
                      },
                      unit: 'Hz', //高通频率
                      editEnable: true,
                    )),
                Obx(() => Xielv(
                      index: c.slope.value, //高通斜率
                      onPress: (slope) => c.setSlope(slope: slope),
                    )),
              ]),
        );
      },
    );
    final btnSize = Size(50, 20);
    final btnStyle = TextStyle(fontSize: 10);
    child = Column(
      children: [
        child,
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            Obx(() => ZFButton(
                  title: highPass ? 'HPF' : 'LPF',
                  size: btnSize,
                  style: btnStyle,
                  selected: highPass
                      ? (c.passType.value == PassType.high)
                      : (c.passType.value == PassType.low),
                  onPressed: () =>
                      c.setPassType(highPass ? PassType.high : PassType.low),
                )),
            Obx(() => ZFButton(
                  title: 'Bypass',
                  size: btnSize,
                  style: btnStyle,
                  selected: c.passType.value == PassType.all,
                  onPressed: () => c.setPassType(PassType.all),
                )),
            ZFButton(
              title: 'Reset',
              size: btnSize,
              style: btnStyle,
              onPressed: c.resetCurrent,
            ),
          ],
        ),
      ],
    );
    return child;
  }
}
